package edu.wpi.cs509.representation;

import java.util.logging.Logger;

/** 
 * ActionAdd is a specific type of action whereby
 * a piece is being added to the board (moved from graveyard to
 * one of the on-board locations).  This typically occurs when the
 * user is setting up the board at the beginning of the game, but
 * it also can happen as part of a rescue.
 * @author cwinsor
 */
public class ActionAdd extends ActionBaseClass {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	/**
	 * Constructor
	 * @param name - gives this action a name
	 * @throws ActionCodingErrorException 
	 */
	public ActionAdd(String name, Gameboard gameboard,
			PlayerPiece pce, Location loc) {

		super(name, gameboard, pce, loc);
	}
	
	
	/**
	 * doStrategoRulesCheck- check the move for legality
	 */
	protected void doStrategoRulesCheck() throws ActionNotLegalException {
		
		// debug message
		Logger.getLogger("global").info("here");
		
		// check the destination location is not the boneyard
		if (isBoneyardDestination()) {
			setErrMessage("ActionAdd - the destination was the boneyard");
			throw new ActionNotLegalException();
		}	

		// check the destination is occupiable (not the lake) 
		if (!isOccupiableDestination()) {
			setErrMessage("ActionAdd - destination is not occupiable");
			throw new ActionNotLegalException();	
		}

		// check the destination is on my half of the board
		if (!destinationIsOnMyHalfOfBoard()) {
			setErrMessage("ActionAdd - destination is not on your half of the board");
			throw new ActionNotLegalException();	
		}

		// check there is not a part on the destination
		if (isAnAttack()) {
			setErrMessage("ActionAdd - there is a part on the destination");
			throw new ActionNotLegalException();
		}
	}


	/**
	 * doExecute - perform the action
	 * will throw an exception if the move is illegal	
	 */
	protected void doExecute() throws ActionNotLegalException, ActionEndOfGameException  {

		// debug message
		Logger.getLogger("global").info("here");

		// execute the move (generic)
		super.doExecute();

		return;
	}

}

